package org.dromara.yuanshidian.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.yuanshidian.domain.vo.Ab03NewVo;
import org.dromara.yuanshidian.domain.bo.Ab03NewBo;
import org.dromara.yuanshidian.service.IAb03NewService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 新离退人员信息
 *
 * @author TzhongTop
 * @date 2025-01-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/yuanshidian/ab03new")
public class Ab03NewController extends BaseController {

    private final IAb03NewService ab03NewService;

    /**
     * 查询新离退人员信息列表
     */
    //@SaCheckPermission("yuanshidian:ab03new:list")
    @GetMapping("/list")
    public TableDataInfo<Ab03NewVo> list(Ab03NewBo bo, PageQuery pageQuery) {
        return ab03NewService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出新离退人员信息列表
     */
    //@SaCheckPermission("yuanshidian:ab03new:export")
    @Log(title = "新离退人员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(Ab03NewBo bo, HttpServletResponse response) {
        List<Ab03NewVo> list = ab03NewService.queryList(bo);
        ExcelUtil.exportExcel(list, "新离退人员信息", Ab03NewVo.class, response);
    }

    /**
     * 获取新离退人员信息详细信息
     *
     * @param ID 主键
     */
    //@SaCheckPermission("yuanshidian:ab03new:query")
    @GetMapping("/{ID}")
    public R<Ab03NewVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long ID) {
        return R.ok(ab03NewService.queryById(ID));
    }

    /**
     * 新增新离退人员信息
     */
    //@SaCheckPermission("yuanshidian:ab03new:add")
    @Log(title = "新离退人员信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody Ab03NewBo bo) {
        return toAjax(ab03NewService.insertByBo(bo));
    }

    /**
     * 修改新离退人员信息
     */
    //@SaCheckPermission("yuanshidian:ab03new:edit")
    @Log(title = "新离退人员信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody Ab03NewBo bo) {
        return toAjax(ab03NewService.updateByBo(bo));
    }

    /**
     * 删除新离退人员信息
     *
     * @param IDs 主键串
     */
    //@SaCheckPermission("yuanshidian:ab03new:remove")
    @Log(title = "新离退人员信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] IDs) {
        return toAjax(ab03NewService.deleteWithValidByIds(List.of(IDs), true));
    }
}
